<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" href="/css/pintuer.css">
    <link rel="stylesheet" href="/css/admin.css">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script type="text/javascript" src="/layui/layui.js"></script>
    <script type="text/javascript" src="/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="/js/vue.js"></script>
</head>
<body>
<div class="panel admin-panel" id="app">
    <div class="panel-head" id="add">
        <strong><span class="icon-pencil-square-o"></span>新增合同扫描件</strong>
    </div>

    <div class="body-content">
        <form id="form" class="form-x">
            <div class="form-group">
                <div class="label">
                    <label>项目id：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" value="" name="conf" id="contractProjectId"/>
                </div>
            </div>


            <div class="form-group">
                <div class="label">
                    <label>审核状态：</label>
                </div>
                <select class="input" id="contractStatus"
                        style="width: 200px; line-height: 17px;">
                    <!--						<option value=0 >请选择审核状态</option>-->
                    <!--						<option value=1>已审核</option>-->
                    <option value=2>未审核</option>
                </select>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>合同图片：</label>
                </div>
                <button type="button" class="layui-btn" onclick="addOne()">
                    <i class="layui-icon">&#xe67c;</i>添加图片
                </button>
                <!--					<input type="button" value="添加" onclick="addOne()">-->

                <div id="addDiv"></div>
            </div>

            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="button" onclick="insertAccount()">
                        提交
                    </button>

                </div>
            </div>

        </form>
    </div>
</div>
</body>

<script type="text/javascript">
    var html = "<div> <br><input type='file'  multiple='multiple'  name='myfile' id='img' />";

    //var up="<button type='button' class='layui-btn test1' id='test1'> <i class='layui-icon'>&#xe67c;</i>上传图片 </button>"
    function addOne() {
        // document.getElementById("addDiv").innerHTML += "<div> <input type='file' name='myfile' id='img' />"
        $("#addDiv").append(html);
    }

    // var _this;
    // var app=new Vue({
    // 	el:"#app",
    // 	data:{
    // 		operationNum:null,
    //
    // 		//定义查询条件对象
    //
    // 	},
    // 	created:function(){
    // 		_this=this;
    // 		this.selectByExample();
    // 	},
    // 	methods:{
    // 		//查询部门信息
    // 		selectByExample:function(){
    // 			_this=this;
    // 			$.ajax({
    // 				url:"/farmergoods/query",
    // 				type:"get",
    // 				dataType:"json",
    // 				success:function(data){
    // 					_this.category=data.list;
    // 				}
    // 			})
    // 		}
    // 	}
    // });

    var date1 = new Date();
    var date2 = new Date();

    function insertAccount() {
        date1 = date2;
        date2 = new Date();
        if ((date2.getTime() - date1.getTime()) < 5000) {
            alert("请不要重复提交")
        } else {

            var formData = new FormData();
            var list = document.getElementsByName("myfile");
            for (let i = 0; i < list.length; i++) {
                if ((list[i].files[0] != null)) {
                    formData.append("img", list[i].files[0]);
                }
            }
            formData.append("contractProjectId", $("#contractProjectId").val());
            formData.append("contractStatus", $("#contractStatus").val());

            $.ajax({
                url: "/contract/insert",
                type: "post",
                data: formData,
                dataType: "json",
                processData: false,
                contentType: false,
                success: function (data) {
                    alert("新增成功");
                    location.href = "contract.html";
                },
                error: function (error) {
                    alert("新增失败");
                }
            })
        }
    }
</script>
</html>